#include <iostream>
#include <memory>
#include <string>

#include "EpollServer.hpp"

using namespace Epoll;


Response TaskFunc(const Request& req)
{
    Response resp;
    switch(req._op)
    {
        case '+':
            resp._result = req._x + req._y;
            resp._code = 0;
            break;
        case '-':
            resp._result = req._x - req._y;
            resp._code = 0;
            break;
        case '*':
            resp._result = req._x * req._y;
            resp._code = 0;
            break;
        case '/':
            if(req._y == 0) 
            {
                resp._result = 0;
                resp._code = 1;
            }
            else
            {
                resp._result = req._x / req._y;
                resp._code = 0;
            }
            break;
        case '%':
            if(req._y == 0) 
            {
                resp._result = 0;
                resp._code = 2;
            }
            else 
            {
                resp._result = req._x % req._y;
                resp._code = 0;
            }
            break;

        default :
            resp._code = 3;
            break;
    }
    return resp;
}

int main()
{
    std::unique_ptr<Server> ser(new Server(TaskFunc,8088));
    ser->Init();
    ser->Dispatcher();
    return 0;
}